import 'package:chat_example/entity/chat_entity.dart';
import 'package:flutter/widgets.dart';
import 'package:scoped_model/scoped_model.dart';

class ChatModel extends Model {
  List<ChatEntity> chats = [];

  void addEntity(ChatEntity entity) {
    chats.add(entity);
    notifyListeners();
  }

  List<ChatEntity> findWithEntity(String id) =>
      chats.where((item) => item.from == id || item.to == id).toList();

  static ChatModel of(BuildContext context) {
    return ScopedModel.of<ChatModel>(context, rebuildOnChange: true);
  }
}
